package com.komodo.island.gdx.dialog;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actors.Image;
import com.komodo.island.gdx.KomodoIsland;
import com.komodo.island.gdx.screen.Screen;

public abstract class Dialog extends Stage {

	/*
	 * Base class for all dialog when using this class, you have to construct
	 * the object and call init method
	 * 
	 * When you want to derive new class from Dialog you have to override
	 * init(); addElements(); setThePosition(); setTheListener();
	 */

	/*
	 * This ID will help to differ one dialog to another...especially for
	 * handling input, so when you derive dialog, please fill this ID with Input
	 * constant
	 */

	public int ID;

	public Image background;
	protected String backgroundName;

	protected String textureName;
	protected Texture texture;

	protected Screen screen;

	/*
	 * After you construct Dialog object
	 * 
	 * -setBackground
	 */

	
	public KomodoIsland komodoIsland;
	
	public Dialog(float width, float height, boolean stretch, Screen screen, Texture texture, KomodoIsland komodoIsland) {
		super(width, height, stretch);
		this.screen = screen;
		this.texture = texture;
		this.komodoIsland = komodoIsland;
		setting();
		
	}
	

	/*
	 * Init methods,choose only one (initByTexture or initByName) to initialize
	 * the texture in the init()
	 */
	public abstract void init();// set the background here

	public void setting(){
//		initByName();
		init();
		addElements();
		setThePosition();
		setTheListener();
	}
	
	public void initByTexture(Texture texture) {
		this.texture = texture;
	}

	public void initByName() {
		this.texture = new Texture(textureName);
//		this.texture = screen.texture;
	}

	/*
	 * Set the background, you take the region from this texture
	 */

	public void setBackground(int x, int y, int width, int height) {
		this.background = new Image("background", new TextureRegion(texture, x,
				y, width, height));
		background.x = 0;
		background.y = 0;
		addActor(background);

	}

	/*
	 * override these methods to customize when deriving new class based from
	 * dialog..
	 */

	/*
	 * Add the actors
	 */
	public abstract void addElements();

	/*
	 * Set the actors' position to the stage
	 */
	public abstract void setThePosition();

	/*
	 * Set the listener to the actor
	 */
	public abstract void setTheListener();
	

	public void setScreen(Screen screen){
		this.screen =screen;
	}

}
